package top.yuhaitao.core.service.impl;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import top.yuhaitao.core.pojo.ProductCategory;
import top.yuhaitao.core.repository.ProductCatetoryRepository;
import top.yuhaitao.core.service.ProductCategoryService;

@Service
public class ProductCatgoryServiceImpl implements ProductCategoryService {

    @Autowired
    private ProductCatetoryRepository productCatetoryRepository;

    @Override
    public ProductCategory findOne(Long categoryId) {
        Optional<ProductCategory> findById = productCatetoryRepository.findById(categoryId);
        return findById.orElse(new ProductCategory());
    }

    @Override
    public List<ProductCategory> findAll() {
        return productCatetoryRepository.findAll();
    }

    @Override
    public List<ProductCategory> findByCategoryTypeIn(List<Integer> categoryTypeListIds) {
        return productCatetoryRepository.findByCategoryTypeIn(categoryTypeListIds);
    }

    @Override
    public ProductCategory save(ProductCategory productCategory) {
        return productCatetoryRepository.save(productCategory);
    }

}
